package com.hmy.infrastructure.client.corpsearch;

import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.common.result.Results;
import com.hmy.ccp.error.annotations.HmyFeignController;
import com.hmy.infrastructure.api.bo.request.corpsearch.CorpDetailSearchRequest;
import com.hmy.infrastructure.api.bo.request.corpsearch.CorpSearchRequest;
import com.hmy.infrastructure.api.bo.response.corpsearch.CorpDetailClientResponse;
import com.hmy.infrastructure.api.bo.response.corpsearch.CorpSearchResponse;
import com.hmy.infrastructure.service.corpsearch.ICorpSearchService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 企业信息三方数据查询API控制器
 *
 * @author songkf
 */
@RestController
@HmyFeignController
public class CorpSearchClientController {

    @Resource
    private ICorpSearchService corpSearchService;

    /**
     * 根据企业名称进行企业列表查询（模糊匹配）
     *
     * @param corpSearchRequest {@link CorpSearchRequest} 企业集合模糊查询参数
     * @return {@link CorpSearchResponse} 企业模糊查询集合
     * @author songkf
     */
    @PostMapping("/feign/corp-search/list")
    public FeignResult<CorpSearchResponse> corpListSearch(@Validated @RequestBody CorpSearchRequest corpSearchRequest) throws Exception {
        return Results.newSuccessResult(corpSearchService.nameSearch(corpSearchRequest));
    }

    /**
     * 根据企业全称从三方查询工商详细信息
     *
     * @param detailSearchRequest {@link CorpDetailSearchRequest} 企业工商详细信息查询参数
     * @return {@link CorpDetailClientResponse} 企业工商详细信息
     * @author songkf
     */
    @PostMapping("/feign/corp-search/detail")
    public FeignResult<CorpDetailClientResponse> corpDetailSearch(@Validated @RequestBody CorpDetailSearchRequest detailSearchRequest) throws Exception {
        return Results.newSuccessResult(corpSearchService.detailSearch(detailSearchRequest));
    }
}
